package com.kun.controller;

import java.util.Map;

import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.kun.entity.Activity;
import com.kun.service.ActivityService;

/**
 * @description: 文章活动
 * @author: KM
 * 2018年5月3日 下午7:01:13
 */
@Controller
@RequestMapping("/activity")
public class ActivityController{
	
	
	@Autowired
	private ActivityService activityService;
	
	@RequestMapping("/{id}")
	public String getActivity(@PathVariable("id") int id,Model model){
		Activity activity = activityService.selectActivityByKey(id);
		if("1".equals(activity.getIsAuth())){//认证会员查看
			if(!SecurityUtils.getSubject().isAuthenticated()){
				return "redirect:/login";
			}else{
				if(!SecurityUtils.getSubject().isPermitted("userActivity:view")){
					return "redirect:/403";
				}
			}
		}
		model.addAttribute("activity", activity);
		return "/activity_detail";
	}

	@RequestMapping("")
    public String activity(){
        return "/activity";
    }
	
	@RequestMapping("/activityPage")
	@ResponseBody
    public Map<String,Object> activityPage(@RequestParam("begin") int begin,@RequestParam("length") int length,String jsonString){
		Map<String,Object> map = activityService.selectActivityTiltle(begin, length, jsonString, false);
        return map;
    }
}
